package priv.mill.bigdata.mapper;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

/**
 * KEYIN:一行文本的起始偏移量 Long
 * VALUEIN: 一行文本的内容 
 * KEYOUT:处理完成后逻辑的key 单词本身, 
 * VALUEOUT 处理完成后的value 单词出现次数
 * @author mill
 *
 */
public class WordCountMapper extends Mapper<LongWritable,Text, Text, IntWritable>{

	/**
	 * maptask 会把所有的行迭代执行一次
	 */
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context)
			throws IOException, InterruptedException {
		
		String line = value.toString();
		String[] split = line.split(" ");
		for (String word : split) {
			context.write(new Text(word), new IntWritable(1));
		}
	}

}
